package com.shenzhen.horselive.presenter;





import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.api.ApiService;

import java.lang.ref.WeakReference;

public abstract class BasePresenter<V extends BaseView> {

    protected ApiService apiService;
    private WeakReference<V> view;

    public void onAttach(V view) {
        this.apiService = ApiFactory.getApiService();
        this.view = new WeakReference<>(view);
    }

    protected V getView() {
        return isViewAttached() ? view.get() : null;
    }

    protected boolean isViewAttached() {
        return null != view && null != view.get();
    }

    public void onDetach() {
        if (view != null) {
            view.clear();
            view = null;
        }
    }
}
